package com.gm.wj.service;

//import jdk.internal.jline.internal.Nullable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import reactor.util.annotation.Nullable;

import java.time.LocalDateTime;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {
    //3.添加定时任务
//    @Scheduled(cron = "0/5 * * * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    private void configureTasks() {
        System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
    }

    @Bean
    @Nullable
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler();
        threadPoolScheduler.setThreadNamePrefix("SockJS-");
        threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
        threadPoolScheduler.setRemoveOnCancelPolicy(true);
        return threadPoolScheduler;
    }

//    @Bean
////    @Nullable
//    public TaskScheduler defaultSockJsTaskScheduler() {
////        if (this.initHandlerRegistry().requiresTaskScheduler()) {
////            ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler();
////            threadPoolScheduler.setThreadNamePrefix("SockJS-");
////            threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
////            threadPoolScheduler.setRemoveOnCancelPolicy(true);
////            this.scheduler = threadPoolScheduler;
////        }
//
//        ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler();
//        threadPoolScheduler.setThreadNamePrefix("SockJS-");
//        threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
//        threadPoolScheduler.setRemoveOnCancelPolicy(true);
//        return threadPoolScheduler;
////        return this.scheduler;
//    }

//————————————————
//    版权声明：本文为CSDN博主「kzcming」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//    原文链接：https://blog.csdn.net/kzcming/article/details/102390593
}
